package com.lemon.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.system.domain.BiElementConfig;
import com.lemon.system.service.IBiElementConfigService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.page.TableDataInfo;

/**
 * 包名称：com.lemon.system.controller
 * 类名称：BiElementConfigController
 * 类描述：要素配置Controller
 * 创建人：@author huangpeng
 * 创建时间：2023-03-12
 */
@RestController
@RequestMapping("/elementConfig")
public class BiElementConfigController extends BaseController {

    @Autowired
    private IBiElementConfigService biElementConfigService;

    /**
     * 查询要素配置列表
     * @Title: list
     * @Description: 查询要素配置列表
     * @param biElementConfig 要素配置
     * @return: TableDataInfo
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:list")
    @GetMapping("/list")
    public TableDataInfo list(BiElementConfig biElementConfig) {
        startPage();
        List<BiElementConfig> list = biElementConfigService.selectBiElementConfigList(biElementConfig);
        return getDataTable(list);
    }

    /**
     * 导出要素配置列表
     * @Title: export
     * @Description: 导出要素配置列表
     * @param response 客户端响应对象
     * @param biElementConfig 要素配置
     * @return:
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:export")
    @Log(title = "要素配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiElementConfig biElementConfig) {
        List<BiElementConfig> list = biElementConfigService.selectBiElementConfigList(biElementConfig);
        ExcelUtil<BiElementConfig> util = new ExcelUtil<BiElementConfig>(BiElementConfig.class);
        util.exportExcel(response, list, "要素配置数据");
    }

    /**
     * 获取要素配置详细信息
     * @Title: getInfo
     * @Description: 获取要素配置详细信息
     * @param id 要素配置主键
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(biElementConfigService.selectByPrimaryKey(id));
    }

    /**
     * 新增要素配置
     * @Title: add
     * @Description: 新增要素配置
     * @param biElementConfig 要素配置
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:add")
    @Log(title = "要素配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiElementConfig biElementConfig) {
        return toAjax(biElementConfigService.insert(biElementConfig));
    }

    /**
     * 修改要素配置
     * @Title: edit
     * @Description: 修改要素配置
     * @param biElementConfig 要素配置
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:edit")
    @Log(title = "要素配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiElementConfig biElementConfig) {
        return toAjax(biElementConfigService.update(biElementConfig));
    }

    /**
     * 删除要素配置
     * @Title: remove
     * @Description: 删除要素配置
     * @param ids 需要删除的要素配置主键集合
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-03-12
     */
    @RequiresPermissions("system:elementConfig:remove")
    @Log(title = "要素配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(biElementConfigService.deleteByBatch(ids));
    }

    /**
     * 通过功能代码查询要素详情信息
     * @Title: queryByFunctionCodes
     * @Description: 通过功能代码查询要素详情信息
     * @param functionCodes
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/3/12 21:13
     */
    @RequiresPermissions("system:elementConfig:list")
    @GetMapping("/queryByFunctionCodes")
    public AjaxResult queryByFunctionCodes(@RequestParam("functionCodes") String functionCodes) {
        return AjaxResult.success(biElementConfigService.queryByFunctionCodes(functionCodes));
    }
}
